﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SQL_Provider;
using System.Data;
using System.Data.SqlClient;
using BusinessEntities;

namespace DataAccess
{
    public class TaiKhoan_Adapter
    {
        Provider db;
        public TaiKhoan_Adapter()
        {
            db = new Provider();
        }
        public DataTable TaiKhoanDN_TimTheoTenTK(string taikhoan, string matkhau)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@TaiKhoan", taikhoan);
            para[1] = new SqlParameter("@MatKhau", matkhau);
            return db.Execute_Table("TaiKhoanDN_TimTheoTenTK", para, CommandType.StoredProcedure);
        }

        public DataTable TaiKhoanDN_All()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("TaiKhoanDN_All", para, CommandType.StoredProcedure);
        }

        public DataTable NhanVien_KoTK()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("NhanVien_KoTK", para, CommandType.StoredProcedure);
        }

        public DataTable NhanVien_KoTK_TimTheoMaNV(string MaNV)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaNV", MaNV);
            return db.Execute_Table("NhanVien_KoTK_TimTheoMaNV", para, CommandType.StoredProcedure);
        }

        public int TaiKhoanDN_Them(TaiKhoan_Info info)
        {
            SqlParameter[] para = new SqlParameter[5];
            para[0] = new SqlParameter("@TaiKhoan", info.TaiKhoan);
            para[1] = new SqlParameter("@MatKhau", info.MatKhau);
            para[2] = new SqlParameter("@ChucVu", info.ChucVu);
            para[3] = new SqlParameter("@MaNV", info.MaNV);
            para[4] = new SqlParameter("@TenNV", info.TenNV);
            return db.Execute_Modify("TaiKhoanDN_Them", para, CommandType.StoredProcedure);
        }

        public int TaiKhoanDN_CapNhat_CauHoi(TaiKhoan_Info info)
        {
            SqlParameter[] para = new SqlParameter[3];
            para[0] = new SqlParameter("@TaiKhoan", info.TaiKhoan);
            para[1] = new SqlParameter("@CauHoiBiMat", info.CauHoiBiMat);
            para[2] = new SqlParameter("@CauTraLoi", info.TraLoi);
            return db.Execute_Modify("TaiKhoanDN_CapNhat_CauHoi", para, CommandType.StoredProcedure);
        }

        public int TaiKhoanDN_ThayDoiMK(string TaiKhoan, string MatKhau, string MatKhauMoi)
        {
            SqlParameter[] para = new SqlParameter[3];
            para[0] = new SqlParameter("@TaiKhoan", TaiKhoan);
            para[1] = new SqlParameter("@MatKhau", MatKhau);
            para[2] = new SqlParameter("@MatKhauMoi", MatKhauMoi);
            return db.Execute_Modify("TaiKhoanDN_ThayDoiMK", para, CommandType.StoredProcedure);
        }

        public DataTable TaiKhoanDN_LayMatKhau(string TaiKhoan, string CauHoiBiMat, string CauTraLoi)
        {
            SqlParameter[] para = new SqlParameter[3];
            para[0] = new SqlParameter("@TaiKhoan", TaiKhoan);
            para[1] = new SqlParameter("@CauHoiBiMat", CauHoiBiMat);
            para[2] = new SqlParameter("@CauTraLoi", CauTraLoi);
            return db.Execute_Table("TaiKhoanDN_LayMatKhau", para, CommandType.StoredProcedure);
        }
        public string TaiKhoanDN_LayCauHoiBiMat(string TaiKhoan)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@TaiKhoan", TaiKhoan);
            return Convert.ToString(db.Execute_Scalar("TaiKhoanDN_LayCauHoiBiMat", para, CommandType.StoredProcedure));
        }
        public int TaiKhoanDN_UpDateMatKhau(string TaiKhoan, string Matkhaumoi, string Matkhaunhaplai)
        {
            SqlParameter[] para = new SqlParameter[3];
            para[0] = new SqlParameter("@TaiKhoan", TaiKhoan);
            para[1] = new SqlParameter("@MaKhauMoi", Matkhaumoi);
            para[2] = new SqlParameter("@MaKhauNhapLai", Matkhaunhaplai);
            return db.Execute_Modify("TaiKhoanDN_UpdateMK", para, CommandType.StoredProcedure);
        }
    }
}
